var t = require("../../@babel/runtime/helpers/interopRequireDefault"), e = require("../../@babel/runtime/helpers/toConsumableArray"), a = t(require("../../@babel/runtime/regenerator")), r = require("../../@babel/runtime/helpers/asyncToGenerator"), n = getApp(), i = require("../../http/productApi.js");

Page({
    data: {
        systemInfo: n.data.systemInfo,
        title: null,
        productList: [],
        hasMore: !0,
        loadingMore: !1
    },
    onLoad: function(t) {
        this.ipId = t.ipId, this.waterFallView = this.selectComponent("#waterFallView"), 
        this.loadIpInfo(), this.loadProductList(!0);
    },
    scrollOnBottom: function() {
        this.loadProductList(!1);
    },
    loadIpInfo: function() {
        var t = this;
        return r(a.default.mark(function e() {
            var r;
            return a.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.prev = 0, e.next = 3, i.ipInfo(t.ipId);

                  case 3:
                    r = e.sent, t.setData({
                        title: r.data.ipEnglishName || r.data.ipName
                    }), e.next = 10;
                    break;

                  case 7:
                    e.prev = 7, e.t0 = e.catch(0), console.log(e.t0);

                  case 10:
                  case "end":
                    return e.stop();
                }
            }, e, null, [ [ 0, 7 ] ]);
        }))();
    },
    loadProductList: function(t) {
        var n = this;
        return r(a.default.mark(function r() {
            var o, s, l;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (t && (n.setData({
                        productList: [],
                        hasMore: !0
                    }), n.waterFallView.initData(null, null)), n.data.hasMore && !n.data.loadingMore) {
                        a.next = 3;
                        break;
                    }
                    return a.abrupt("return");

                  case 3:
                    return 20, o = n.data.productList.length / 20 + 1, n.setData({
                        loadingMore: !0
                    }), a.prev = 6, a.next = 9, i.productListByIp({
                        ipId: n.ipId
                    }, o, 20);

                  case 9:
                    s = a.sent, l = [].concat(e(n.data.productList), e(s.data.list)), n.setData({
                        inited: !0,
                        productList: l,
                        hasMore: s.data.totalPage > s.data.currPage
                    }), 1 == s.data.currPage ? n.waterFallView.initData(null, s.data.list) : n.waterFallView.appendProducts(s.data.list), 
                    a.next = 18;
                    break;

                  case 15:
                    a.prev = 15, a.t0 = a.catch(6), console.log(a.t0);

                  case 18:
                    return a.prev = 18, n.setData({
                        loadingMore: !1
                    }), a.finish(18);

                  case 21:
                  case "end":
                    return a.stop();
                }
            }, r, null, [ [ 6, 15, 18, 21 ] ]);
        }))();
    }
});